{extend name="public/base" /}

{block name="title"}<title>{$Think.lang.list}</title>{/block}

{block name="pjax_container"}
<div class="hry-content-wrapper">
<section class="content-header">
    <ol class="breadcrumb">
        <li>合同管理</li>
        <li class="active">合同列表</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="hry-form-wrapper">
                <div class="box-header with-border">
                    <h3 class="box-title"></h3>
                    <div class="pull-left">
                        <!--{:authAction(CONTROLLER_NAME.'/create', 'create')}-->
                        {:authAction(CONTROLLER_NAME.'/crecontract', 'crecontract')}
                    </div>
                </div>
                <div class="box-body table-responsive">
                    <table class="table table-bordered table-hover table-sort">
                        <tr>
                            <th>{$Think.lang.id}{:table_sort('id')}</th>
                            <th>logo</th>
                            <th>合同名称</th>
                            <th>FID</th>
                            <th>所属项目</th>
                            <th>修改时间</th>
                            <th>截止日期</th>
                            <th>状态</th>
                            <th width="300">{$Think.lang.action}</th>
                        </tr>
                        {volist name="dataList" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td><img src="/uploads/contract/{$vo.logo}" alt="" width="50"></td>
                            <td>{$vo.title}</td>
                            <td>{$vo.fid}</td>
                            <td>{$vo.Project.project_name}</td>
                            <td>{$vo.date}</td>
                            <td>{$vo.expiretime}</td>
                            <td>{if $vo.issend eq 0}
                            未生成
                            {elseif $vo.issend eq 1}
                            待签署
                            {elseif $vo.issend eq 2}
                            待签章
                            {elseif $vo.issend eq 3}
                            待发送
                            {elseif $vo.issend eq 4}
                            已发送
                            {/if}
                            </td>

                            <td>
                                <a class="btn-text btn-primary btn-xs btnSubmit up-contract" data-id="{$vo.id}" data-url="{:url('Hetong/contractLogoUpload')}">上传图片</a>
                                {if $vo.issend eq 0}
                                <a class="btn-text btn-primary btn-xs btnSubmit ss" data-id="{$vo.id}">生成合同</a>
                                {elseif $vo.issend eq 1}
                                <a class="btn-text btn-primary btn-xs btnSubmit yh" data-id="{$vo.id}">用户签署</a>
                                {elseif $vo.issend eq 2 }
                                <a class="btn-text btn-primary btn-xs btnSubmit gs" data-id="{$vo.id}">公司签章</a>
                                {elseif $vo.issend eq 3 }
                                <a class="btn-text btn-primary btn-xs btnSubmit fs" data-id="{$vo.id}">发送合同</a>
                                {/if}
                                <a class="btn-text btn-primary btn-xs btnSubmit ck" data-id="{$vo.id}">查看合同</a>

                                {include file="public/ht_action" /}
                            </td>
                        </tr>
                        {/volist}
                    </table>
                </div>
                <div class="box-footer clearfix">
                    {$dataList->render()}
                </div>
            </div>
        </div>
    </div>
</section>
</div>
<script type="text/javascript">
    $(function(){
        /*ajax页面加载icheck，有该控件的页面才需要*/
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });

        /*ajax页面加载icheck，有该控件的页面才需要*/
        $(".select2").select2({language:"zh-CN"});

        /*全选-反选*/
        $('.checkbox-toggle').on('ifChecked', function(event){
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("check");
        });
        $('.checkbox-toggle').on('ifUnchecked', function(event){
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("uncheck");
        });

        $('.editable').editable({
            emptytext: "empty",
            params: function(params) {      //参数
                var data = {};
                data['id'] = params.pk;
                data[params.name] = params.value;
                return data;
            },
            success: function(response, newValue) {
                var res = $.parseJSON( response );
                if(res.status == 1){
                }else{
                    return res.info;
                }
            }
        });

        {if condition=" $rest_login == 1 "}
        restlogin('{$rest_login_info}');   //登录超时
        {/if}
        })
    $(".up-contract").on('click','', function(){   //点击生成合同
        var _this_up_btn = $(this);   //当前上传按钮
        var up_url = _this_up_btn.data('url');   //上传地址
        var up_id = _this_up_btn.data('id');   //上传id

        BootstrapDialog.confirm({
            title: "上传 - Upload",
            message: '<form method="POST" action="'+up_url+'" enctype="multipart/form-data" ><input type="file" name="imgFile" class="Uploads" /></form>',
            btnCancelLabel: '取消',
            btnOKLabel: '确定并提交',
            callback: function(result) {
                if(result) {
                    var form = $('.modal-dialog').find('form');
                    var ajax_option={
                        dataType:'json',
                        success:function(data){
                            console.log(data)
                            if(data.status == 1){
                                submitLogo(data.data.logo, up_id)
                            }else{
                                $.amaran({'message':data.info});
                            }
                        }
                    }
                    form.ajaxSubmit(ajax_option);
                }
            }
        });
    });
    function submitLogo(logo, id){
        $.ajax({
            url:"contractLogoEdit",
            data:{
                contract_id:id,
                logo:logo
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                if(JSON.status == 1){
                    $.amaran({'message':'上传成功'});
                    window.location.href = JSON.url
                }
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    }
    $(".ss").on('click','', function(){   //点击生成合同
        data=$(this).data("id");
        $.ajax({
            url:"batchht",
            data:{
                id:data
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                console.log(JSON);
                $.amaran({'message':JSON.info,'url':JSON.url})
                // window.location.href = JSON.url;
//                    debugger;
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    });
    $(".ck").on('click','', function(){
        data=$(this).data("id");
        $.ajax({
            url:"lookht",
            data:{
                id:data
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                console.log(JSON);
                $.amaran({'message':JSON.info,'url':JSON.url})
                //window.location.href = JSON.url;
//                    debugger;
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    });
//公司签章
    $(".gs").on('click','', function(){
        data=$(this).data("id");
        $.ajax({
            url:"batchstamp",
            data:{
                id:data
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                console.log(JSON);
                $.amaran({'message':JSON.info,'url':JSON.url})
                //window.location.href = JSON.url;
//                    debugger;
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    });

    $(".yh").on('click','', function(){
        data=$(this).data("id");
        $.ajax({
            url:"usersign",
            data:{
                id:data
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                console.log(JSON);
                $.amaran({'message':JSON.info,'url':JSON.url})
                //window.location.href = JSON.url;
//                    debugger;
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    });
    $(".fs").on('click','', function(){
        data=$(this).data("id");
        $.ajax({
            url:"sendht",
            data:{
                id:data
            },
            type:"POST",
            dataType:"json",
            success:function(JSON){
                console.log(JSON.url);
                $.amaran({'message':JSON.info,'url':JSON.url});
//                    debugger;
            },
            error:function(xhr,status,errorThrown){
//                    debugger;
            },
            complete:function(xhr,status){
//                    alert('The request is complated');
            },
            beforesend:function(){
            },
            cache:false,//true
            async:true
        });//ajax end here
    });
</script>
{/block}